<template>
  <div id="app">
    <transition  :name="direction" >
      <router-view class="appView" v-wechat-title="$route.meta.title"/>
    </transition>
  </div>
</template>

<script>
  export default {
    name: 'App',
    data: () => ({
      direction: "slide-right"
    }),
    watch: {
      $route(to, from) {
        const toDepth = to.path.split("/").length;
        const fromDepth = from.path.split("/").length;
        if (to.path == "/") {
          this.direction = "slide-right";
        } else if (from.path == "/") {
          this.direction = "slide-left";
        }else{
          this.direction = toDepth < fromDepth ? "slide-right" : "slide-left";
        }
      }
    }
  }
</script>

<style>
  html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    background: white;
  }

  #app {
    font-family: 'Avenir', Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-align: center;
    width:100%;
    height:100%;
  }

  .title {
    width: 100%;
    height: 60px;
    line-height: 60px;
    background: white;
  }

  #nextStep {
    width: 50%;
    height: 40px;
    background: dodgerblue;
    color: white;
    position: fixed;
    bottom: 80px;
    left: 25%;
    border:0;
    border-radius: 40px;
  }

  .appView {
    position: absolute;
    width:100%;
    transition: transform 0.3s ease-out;
  }
  .slide-left-enter{
    transform: translate(100%, 0);
  }
  .slide-left-leave-active{
    transform: translate(-100%, 0);
  }
  .slide-right-enter {
    transform: translate(-100%, 0);
  }
  .slide-right-leave-active{
    transform: translate(100%, 0);
  }
</style>
